//		ID : Xerxes
//      "I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define tp pair< int, pair<int,int> >
#define mmk( x, y , z ) mk( x, mk( y, z ) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
string board="         ";
map< string , string > mp;
inline void Print(){
	foE(i,1,9){
		cout<<board[i-1]<<" ";
		if(i%3==0){
			cout<<"\n";
		}
		
	}
	cout<<"\n";
}
inline void gen(){
	mp.clear();
	queue< string > q;
	string nw;
	q.push("123456789");
	mp[ "123456789" ] = "";
	while( q.empty()==false ){
		string t = q.front();
		string s = mp[t];
		q.pop();
		
		//h1 move
		nw = t;
		nw[0]=t[1];nw[1]=t[2];nw[2]=t[0];
		if( !mp.count(nw) ){
			mp[nw]= s+"H1";
			q.push(nw);
		}
		//h2 move
		nw = t;
		nw[3]=t[4];nw[4]=t[5];nw[5]=t[3];
		if( !mp.count(nw) ){
			mp[nw]= s+"H2";
			q.push(nw);
		}
		//h3 move
		nw = t;
		nw[6]=t[7];nw[7]=t[8];nw[8]=t[6];
		if( !mp.count(nw) ){
			mp[nw]= s+"H3";
			q.push(nw);
		}
		//v1 move
		nw = t;
		nw[3]=t[0];nw[6]=t[3];nw[0]=t[6];
		if( !mp.count(nw) ){
			mp[nw]= s+"V1";
			q.push(nw);
		}
		//v2 move
		nw = t;
		nw[4]=t[1];nw[7]=t[4];nw[1]=t[7];
		if( !mp.count(nw) ){
			mp[nw]= s+"V2";
			q.push(nw);
		}
		//v3 move
		nw = t;
		nw[5]=t[2];nw[8]=t[5];nw[2]=t[8];
		if( !mp.count(nw) ){
			mp[nw]= s+"V3";
			q.push(nw);
		}
		
		
		
	}
}
inline void Read(int x){
	int y;
	fo(i,0,9){
		if(x){
			board[i]=x+'0';
			x=0;
		}
		else{
			CI(y);
			board[i]=y+'0';
		}
	}
	
}
inline void Proc(){
	if( !mp.count(board) ){
		cout<<"Not solvable\n";
	}
	else{
		string ss = mp[board];
		int len = LN(ss);
		string tmp="";
		for(int i=0;i+1<len;i+=2){
			tmp+=ss[len-(i+1+1) ];
			tmp+=ss[len-(i+1) ];
		}
		cout<<len/2<<" "<<tmp<<"\n";
	}
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in","rt",stdin);
    #endif
    gen();
	int x;
	while( scanf("%d",&x)==1 ){
		if( x==0 )break;
		Read(x);
		Proc();		
	}

return 0;
}


